#pragma once
#pragma once
#include "Common.h"
#include "ObjectPool.h"
#include "PageMap.h"

class PageCache
{
public:
	static PageCache *GetInstance()
	{
		return &_sInstPageCache;
	}
	//获取一个k页的span
	Span *NewSpan(size_t k);
	std::mutex &GetMutex()
	{
		return _pageMtx;
	}
	//获取对象到span的映射
	Span *MapObjectToSpan(void *obj);

	//释放空闲span回到Pagecache，合并相邻的span
	void ReleaseSpanToPageCache(Span *span);

private:
	SpanList _spanLists[NPAGES];
	ObjectPool<Span> _spanPool;

	//不使用桶锁
	std::mutex _pageMtx;
	//记录页号和span的映射
	// std::unordered_map<PAGE_ID, Span*>_idSpanMap;

	TCMalloc_PageMap _idSpanMap;

	PageCache(){};
	PageCache(const PageCache &) = delete;
	static PageCache _sInstPageCache;
};